//
//  SecondViewController.m
//  UI_元旦豆瓣
//
//  Created by dllo on 16/1/9.
//  Copyright © 2016年 31付冬梅. All rights reserved.
//

#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "AfraDataBase--MovieActivity.h"
#import "ActivityModel.h"
#import "UIImageView+WebCache.h"
#import "MovieModel.h"
#import "AfraDataBase2016010902Movie.h"

@interface SecondViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *dataBaseArr;
@property (nonatomic, retain) NSMutableArray *movieDBArr;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.title = self.str;
    self.view.backgroundColor = [UIColor yellowColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    
    self.dataBaseArr = [[AfraDataBase__MovieActivity sharedInstenceDataBaseHandle] selectTable];
    [_tableView reloadData];
    
    self.movieDBArr = [[AfraDataBase2016010902Movie sharedDataBaseMovieHandle] selectMovieTable];
    [_tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataBaseArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if ([_str isEqualToString:@"我的活动"]) {
        for (ActivityModel *model in _dataBaseArr) {
            NSLog(@"%@ %@", model.title, model.image);
        }
        ActivityModel *model = _dataBaseArr[indexPath.row];
        
        cell.textLabel.text = model.title;
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
        
        
    }
    if ([_str isEqualToString:@"我的电影收藏"]) {
        
            MovieModel *model = _movieDBArr[indexPath.row];
            cell.textLabel.text = model.title;
            [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
        
    }
    
    return cell;
}
//点击cell
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    ThirdViewController *thVc = [[ThirdViewController alloc] init];
    
    [self.navigationController pushViewController:thVc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
